package com.chuji.crmcj.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.chuji.crmcj.R;
import com.chuji.crmcj.act.InsureCalAct;
import com.chuji.crmcj.utils.UIUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by w.pitt on 2016/2/25.
 */
public class GvInsureAda extends BaseAdapter {

    private ViewHolder holder;

    private List<String> mInsures = new ArrayList<String>(Arrays.asList("交强险", "车身划痕险", "第三者险", "玻璃单独破碎险", "全车盗抢险", "车身随时险", "自燃损失险", "不计免赔险", "无过责任险", "车上人员责任险", "涉水险"));
    private List<Boolean> mCheck = new ArrayList<Boolean>();
    private GridView mGvExtraInsure;
    private Context mContext;

    public GvInsureAda(InsureCalAct insureCalAct, GridView mGvExtraInsure) {
        this.mGvExtraInsure = mGvExtraInsure;
        this.mContext = insureCalAct;
    }

    @Override
    public int getCount() {
        return mInsures.size();
    }

    @Override
    public Object getItem(int position) {
        return mInsures.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
//        if (convertView == null) {
//            convertView = View.inflate(UIUtils.getContext(), R.layout.layout_extra_insure, null);
//            holder = new ViewHolder();
//            holder.iv_check = (ImageView) convertView.findViewById(R.id.iv_check1);
//            holder.tv_extra_name = (TextView) convertView.findViewById(R.id.tv_extra_name);
//            holder.tv_extra_cost = (TextView) convertView.findViewById(R.id.tv_extra_cost);
//            holder.iv_right = (ImageView) convertView.findViewById(R.id.iv_right);
//            convertView.setTag(holder);
//        } else {
//            holder = (ViewHolder) convertView.getTag();
//        }
//        mCheck.add(position, false);
//        holder.tv_extra_name.setText(mInsures.get(position));
////        holder.tv_extra_cost.setText("11111111111");
//        if (position == 0 || position == 1 || position == 2 || position == 3) {
//            holder.iv_right.setVisibility(View.VISIBLE);
//        }
//        holder.iv_check.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (mCheck.get(position)) {
//                    holder.iv_check.setImageDrawable(UIUtils.getDrawable(R.drawable.uncheck));
//                    mCheck.add(position, false);
//                } else {
//                    holder.iv_check.setImageDrawable(UIUtils.getDrawable(R.drawable.check));
//                    mCheck.add(position, true);
//                }
//            }
//        });
//
//        holder.iv_right.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                switch (position) {
//                    case 0:
//                        lable = 0;
//                        break;
//                    case 1:
//                        lable = 1;
//                        break;
//                    case 2:
//                        lable = 2;
//                        break;
//                    case 3:
//                        lable = 3;
//                        break;
//                }
////                showTestDialog(mContext, lable);
//            }
//        });

//        mGvExtraInsure.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                holder.iv_check.setImageDrawable(UIUtils.getDrawable(R.drawable.check));
//
//                GvInsureAda.this.notifyDataSetChanged();
//            }
//        });
        return convertView;
    }

    private int lable = -1;

    static class ViewHolder {
        private CheckBox iv_check;
        private TextView tv_extra_name;
        private TextView tv_extra_cost;
        private ImageView iv_right;
    }

    protected void showTestDialog(Context mContext, int lable) {

//        final SimpleBottomDialog dialog = new SimpleBottomDialog(lable, mContext);
//        dialog.setOnOKClickListener(new SimpleBottomDialog.OnOKClickListener() {
//            @Override
//            public void onOKClick(View v, int position, Map<String, Double> map, int lable) {
//
//            }
//        });
//        dialog.show();
    }
}
